<taglib name="Admin\TagLib\EasyUI" />

<easyui:datagrid options="datagrid.options" fields="datagrid.fields" />

<!-- 查看任务 -->
<div id="mission_missionlist_view_dialog" class="easyui-dialog" title="任务详情"
     data-options="modal:true,closed:true,iconCls:'icons-application-application_view_detail',
     buttons:[{text:'关闭',iconCls:'icons-arrow-cross',
     handler:function(){$('#mission_missionlist_view_dialog').dialog('close');}}]"
     style="width:450px;height:330px;"></div>



<script type="text/javascript">
    var mission_missionlist_datagrid_toolbar = [
        { text: '刷新', iconCls: 'icons-table-table_refresh', handler: missionMissionRefresh }
    ];

    //操作格式化
    function missionListOperateFormatter(val){
        var btn = [];
        btn.push('<a href="javascript:;" onclick="missionView('+val+')">查看</a>');
        /*btn.push('<a href="javascript:;" onclick="missionBlack('+val+')">拉黑/启用</a>');*/
        btn.push('<a href="javascript:;" onclick="missionDelete('+val+')">删除</a>');
        btn.push('<a href="javascript:;" onclick="missionTop('+val+')">置顶/取消</a>');
        return btn.join(' | ');
    }

    //刷新
    function missionMissionRefresh(){
        $('#mission_missionlist_datagrid').datagrid('reload');
    }

    function missionTop(id){
        if(typeof(id) !== 'number'){
            $.messager.alert('提示信息', '未选择任务', 'error');
            return false;
        }
        $.messager.confirm('提示信息', '确定要进行此操作吗？', function(result){
            if(!result) return false;
            $.post('<{:U('Mission/toTop')}>', {id: id}, function(res){
                if(!res.status){
                    $.messager.alert('提示信息', res.info, 'error');
                }else{
                    $.messager.alert('提示信息', res.info, 'info');
                    missionMissionRefresh();
                }
            }, 'json');
        });
    }
    function missionView(id){
        if(typeof(id) !== 'number'){
            $.messager.alert('提示信息', '未选择用户', 'error');
            return false;
        }
        var url = '<{:U('Mission/missionView')}>';
        url += url.indexOf('?') != -1 ? '&mission_id='+id : '?mission_id='+id;
        $('#mission_missionlist_view_dialog').dialog({href:url});
        $('#mission_missionlist_view_dialog').dialog('open');
    }


    function missionDelete(id){
        if(typeof(id) !== 'number'){
            $.messager.alert('提示信息', '未选择', 'error');
            return false;
        }
        $.messager.confirm('提示信息', '确定要删除吗？', function(result){
            if(!result) return false;
            $.post('<{:U('Mission/missionDelete')}>', {mission_id: id}, function(res){
                if(!res.status){
                    $.messager.alert('提示信息', res.info, 'error');
                }else{
                    $.messager.alert('提示信息', res.info, 'info');
                    missionMissionRefresh();
                }
            }, 'json');
        });
    }
    function missionDurationFormatter(val){
        var strs = new Array();
        strs = val.split(",");
        str = "";
        for(var i=0;i<strs.length;i++){
            switch(strs[i])
            {
                case "1":
                    str += "三天内 ";
                    break;
                case "2":
                    str += "两周内 ";
                    break;
                case "3":
                    str += "三个月内 ";
                    break;
                case "4":
                    str += "长期 ";
                    break;
                default:
                    str += "未定义 ";
            }
        }
        return str;

    }

    function missionStatusFormatter(val){
        switch(val)
        {
            case "1":
                return "新发布 ";

            case "2":
                return "已完成 ";

            case "3":
                return "已取消 ";


            default:
                return "未定义 ";
        }
    }

    function missionValidTimeFormatter(val){
        switch(val)
        {
            case "1":
                return "1天 ";
            case "2":
                return "3天 ";
            case "3":
                return "7天 ";
            case "4":
                return "10天 ";
            case "5":
                return "长期 ";
            default:
                return "未定义 ";
        }
    }
    function missionTopFormatter(val){
        if(val==0||val==null){
            return '否';
        }else{
            return '是';
        }

    }

</script>